import 'package:flutter/material.dart';

main() {
  runApp(Demo6App());
}

class Demo6App extends StatefulWidget {
  const Demo6App({Key? key}) : super(key: key);

  @override
  _Demo6AppState createState() => _Demo6AppState();
}

class _Demo6AppState extends State<Demo6App> {
  List<Tab> tabs = [
    Tab(
      text: '关注',
    ),
    Tab(
      text: '热门',
    ),
    Tab(
      text: '科技',
    ),
    Tab(
      text: '搞笑',
    ),
    Tab(
      text: '社会',
    ),
    Tab(
      text: '法律',
    ),
    Tab(
      text: '人文',
    ),
  ];

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      theme: ThemeData(primaryColor: Colors.greenAccent),
      home: DefaultTabController(
        length: tabs.length,
        child: Scaffold(
          appBar: AppBar(
            bottom: TabBar(
              tabs: tabs,
              isScrollable: true,
              indicatorColor: Colors.yellow,//指示器颜色
              labelColor: Colors.yellow, //选中的文字颜色
              unselectedLabelColor: Colors.white, //未选中的文字颜色
              indicatorSize: TabBarIndicatorSize.label,//指示器宽度
            ),
          ),
          body: TabBarView(
            children: tabs.map((e) {
              return Center(
                child: Text(e.text ?? "没有数据"),
              );
            }).toList(),
          ),
        ),
      ),
    );
  }
}
